<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格全选案例</title>
    <script src="jquery-1.11.3.min.js"></script>
    <style>
        *{padding:0;margin:0;}
        .wrap{
            width:300px;
            margin:100px auto 0;
        }
        table{
            width:300px;
            border-collapse:collapse;
            border:1px solid #c0c0c0;
            text-align:center;
        }
        table thead tr{
            background:#09c;
            color:#fff;
            font-size:16px;
        }
        tbody{
            background:#e4e4e4;
           
        }
        td,th{
             border:1px solid #c0c0c0;
             padding:10px;
            }
    </style>
<script>
    $(function(){
        $("#j_cdAll").click(function(){
            var ck=$(this).prop("checked");//获取当前全选框的值
            $("#j_tb input").prop("checked",ck);//ck属于赋值时不加引号
        });
        $("#j_tb input:checked").click(function(){
            var Allchecked=$("#j_tb input").length;
            var checkedLength=$("#j_tb input:checked").length;//下面所有的input中被选择的那些input
            if(Allchecked==checkedLength)//说明可以全选了
            {
                $("#j_cdAll").prop("checked", true);
            }
            else
            {
                $("#j_cdAll").prop("checked", false);
            }

        });
    });
</script>
</head>
<body>
    <div class="wrap">
        <table>
            <thead>
                <tr>
                    <th><input type="checkbox" id="j_cdAll"></th>
                    <th>菜名</th>
                    <th>饭店</th>
                </tr>
            </thead>
            <tbody id="j_tb">
                <tr>
                    <td><input type="checkbox"></td>
                    <td>红烧肉</td>
                    <td>田老师</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>西红柿鸡蛋</td>
                    <td>田老师</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>红烧狮子头</td>
                    <td>田老师</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td>日式肥牛</td>
                    <td>田老师</td>
                </tr>
            </tbody>
        </table>
    </div>
    
</body>
</html>